package com.zsy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zsy.mapper.LogMapper;
import com.zsy.pojo.OperateLog;
import com.zsy.pojo.PageResult;
import com.zsy.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-14 19:37
 **/
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    /**
     * 获取操作日志列表
     *
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<OperateLog> getLogPage(Integer page, Integer pageSize) {
        // 1.设置分页参数
        PageHelper.startPage(page, pageSize);
        // 2.执行查询
        List<OperateLog> logList = logMapper.getLogPage(page, pageSize);
        // 3.封装数据
        PageInfo<OperateLog> pageInfo = new PageInfo<>(logList);
        // 返回值
        return new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 插入日志
     *
     * @param operateLog
     */
    @Override
    public void insert(OperateLog operateLog) {
        logMapper.insert(operateLog);
    }
}
